home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / ifupdown.postinst < prev    next >
Encoding:
Text File  |  2010-03-03  |  4.6 KB  |  131 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. MYNAME="${0##*/}"
  5.  
  6. report() { echo "${MYNAME}: $*" ; }
  7. report_warn() { report "Warning: $*" >&2 ; }
  8. report_err() { report "Error: $*" >&2 ; }
  9.  
  10. # Create /etc/network/run 
  11. if [ "$1" = configure -a ! -d /etc/network/run ]; then
  12.   if [ -e /etc/network/run -o -L /etc/network/run ]; then
  13.     echo "Renaming non-directory /etc/network/run to run.dpkg-old..."
  14.     mv /etc/network/run /etc/network/run.dpkg-old
  15.   fi
  16.  
  17.   # The best choice is to use /dev/shm/network
  18.   #
  19.   # If we can't use that, we'll just make /etc/network/run a directory,
  20.   # unless we're upgrading, in which case we'll just keep ifstate where it
  21.   # is, by making /etc/network/run a symlink to /etc/network.
  22.  
  23.   WHAT_TO_USE=devshm
  24.  
  25.   if [ ! -d /dev/shm -o ! -w /dev/shm -o ! -r /proc/mounts ]; then
  26.     WHAT_TO_USE=owndir
  27.   elif ! grep -qs "^tmpfs[[:space:]]\+/dev/shm[[:space:]]\+tmpfs[[:space:]]\+\([^[:space:]]\+,\)\?rw" /proc/mounts
  28.   then
  29.     WHAT_TO_USE=owndir
  30.   elif grep -qs '[[:space:]]/dev[[:space:]]devfs[[:space:]]' /proc/mounts; then
  31.     WHAT_TO_USE=owndir
  32.   fi
  33.  
  34.   # Check for available space if we are using devshm
  35.   if [ "$WHAT_TO_USE" = devshm ]; then
  36.     SPACE=`df -k /dev/shm | tail -1 | awk '{if ($4 ~ /%/) { print $3 } else { print $4 } }'`
  37.     if [ "$SPACE" -le 0 ]; then
  38.       WHAT_TO_USE=owndir
  39.     fi
  40.   fi
  41.  
  42.   if [ "$WHAT_TO_USE" = owndir -a -e /etc/network/ifstate ]; then
  43.     WHAT_TO_USE=etcnetwork
  44.   fi
  45.  
  46.   if [ "$WHAT_TO_USE" = devshm ]
  47.   then
  48.     [ -d /dev/shm/network ] || mkdir /dev/shm/network
  49.     ln -s /dev/shm/network /etc/network/run
  50.   elif [ "$WHAT_TO_USE" = "owndir" ]; then
  51.     mkdir /etc/network/run
  52.   else
  53.     ln -s . /etc/network/run
  54.   fi
  55. fi 
  56.  
  57. # Move /etc/network/ifstate to /etc/network/run/ifstate
  58. if [ "$1" = configure -a "$2" != "" -a -e /etc/network/ifstate ] &&
  59.      dpkg --compare-versions "$2" lt "0.6.5"
  60. then
  61.   if [ ! -e /etc/network/run/ifstate ] || ! diff /etc/network/ifstate /etc/network/run/ifstate >/dev/null
  62.   then
  63.     echo "Moving /etc/network/ifstate to /etc/network/run/ifstate"
  64.     if [ ! -L /etc/network/ifstate ]; then
  65.       mv /etc/network/ifstate /etc/network/run/ifstate
  66.     else
  67.       cat /etc/network/ifstate >/etc/network/run/ifstate
  68.       mv /etc/network/ifstate /etc/network/ifstate.dpkg-old
  69.     fi
  70.   fi
  71. fi
  72.    
  73. if [ "$1" = "configure" -a "$2" != "" ] &&
  74.      dpkg --compare-versions "$2" le "0.6.4-4.1" &&
  75.      [ -f /etc/network/run/ifstate -a -x /sbin/dhclient ]
  76. then
  77.   # for every active ifupdown-controlled dhclient interface, copy
  78.   # /var/run/dhclient.pid, so that the new ifdown is able to kill
  79.   # dhclient.
  80.   #
  81.   # the old version had a bug with more than one DHCP iface anyway,
  82.   # so we don't know which one the PID file actually belongs to.
  83.  
  84.   sed -e 's/^.*=//' /etc/network/run/ifstate |
  85.     while read iface; do
  86.       # handle \<newline>-continued lines
  87.       if sed -e '/^[[:space:]]*#/b;:g /\\$/{N;s/\\\n//;bg;}' /etc/network/interfaces | grep -qe "^[[:space:]]*iface[[:space:]]*\\b${iface}\\b[[:space:]]*.*\\bdhcp\\b.*" &&
  88.           [ -f "/var/run/dhclient.pid" ] &&
  89.           [ ! -f "/var/run/dhclient.${iface}.pid" ]
  90.       then
  91.         # copy original file.  If dhclient was started
  92.         # manually, one can still use dhclient.pid, if started
  93.         # by ifupdown, the new ifupdown can take it down with 
  94.         # dhclient.${iface}.pid.  Obsolete files are removed during
  95.         # next boot (bootmisc.sh).
  96.         cp /var/run/dhclient.pid "/var/run/dhclient.${iface}.pid"
  97.       fi
  98.     done
  99. fi
  100.  
  101. # Generic stuff done on all configurations
  102. if [ "$1" = "configure" ] ; then
  103.   if [ -f /etc/network/interfaces ] ; then
  104.     # TODO: This should be handled with debconf and the script
  105.     # could introduce the line there directly
  106.     if ! grep -q "^[[:space:]]*iface[[:space:]]\+lo[[:space:]]\+inet[[:space:]]\+loopback\>" /etc/network/interfaces ; then
  107.       report_warn "No 'iface lo' definition found in /etc/network/interfaces"
  108.     fi
  109.     if ! grep -q "^[[:space:]]*auto[[:space:]].*\<lo\>" /etc/network/interfaces ; then
  110.       report_warn "No 'auto lo' statement found in /etc/network/interfaces"
  111.     fi
  112.   else  # ! -f /etc/network/interfaces
  113.     echo "Creating /etc/network/interfaces."
  114.     echo "# interfaces(5) file used by ifup(8) and ifdown(8)" > /etc/network/interfaces
  115.     echo "auto lo" >> /etc/network/interfaces
  116.     echo "iface lo inet loopback" >> /etc/network/interfaces
  117.   fi
  118. fi
  119.  
  120. # Automatically added by dh_installinit
  121. if [ -x "/etc/init.d/ifupdown-clean" ]; then
  122.     update-rc.d ifupdown-clean start 18 S . >/dev/null || exit $?
  123. fi
  124. # End automatically added section
  125. # Automatically added by dh_installinit
  126. if [ -x "/etc/init.d/ifupdown" ]; then
  127.     update-rc.d ifupdown start 39 S . start 36 0 6 . >/dev/null || exit $?
  128. fi
  129. # End automatically added section
  130.  
  131.